<template>
  <!-- 搜索记录 -->
  <div class="search_history">
    <van-cell title="搜索记录">
      <div v-if="isDelete">
        <span @click="handleAllRemoverClick">全部删除</span>&nbsp;&nbsp;&nbsp;
        <span @click="isDelete = !isDelete">完成</span>
      </div>
      <van-icon v-else name="delete" @click="isDelete = !isDelete"></van-icon>
    </van-cell>
    <van-cell
      v-for="(item, index) in searchHistory"
      :key="index"
      :title="item"
      @click="handleRemoveItemClick(item, index)"
    >
      <span>
        <van-icon name="close" />
      </span>
    </van-cell>
  </div>
</template>

<script>
import { deleteSearchHistories } from "@/request/home";

export default {
  props: {
    searchHistory: {
      type: Array,
      defalut() {
        return [];
      }
    }
  },
  data() {
    return {
      isDelete: false
    };
  },
  methods: {
    // 全部删除
    async handleAllRemoverClick() {
      await deleteSearchHistories();
      // 发送事件到父组件发起请求更新数据
      this.$emit("handleAllRemover");
    },
    // 删除单个 
    handleRemoveItemClick(item, index) {

    }
  }
};
</script>

<style>
</style>